<style scoped="scoped">
    @import "directCarDealerApproveDetail.less";
</style>
<template>
    <div>
        <Row >
            <div class="recordInfo_search">
                <a class="select-clear" @click="showBasic">基本信息</a>
                <a class="select-clear" @click="showAccount">收款账号信息</a>
                <a class="select-clear" @click="showAttachment">附件</a>
            </div>
        </Row>
        <div>
        <approveBasic v-bind:channelInfo="this.channelEntry.channelInfo" :recordDetails="this.channelEntry.recordDetails" :isNeedApproval="true"></approveBasic>
        </div>

        <div class="div-entry">
            <Form ref="channelEntry" :model="channelEntry" :rules="channelFormRules" :label-width="140" inline>
                <Divider id="approve-id">审批意见</Divider>
                <Card>
                    <Row>
                        <FormItem label="审批意见" prop="approve"  >
                            <Select v-model="channelEntry.approve" style="width:400px"  placeholder="审批意见" class="w200" @on-change="clearRemark">
                                <Option value="1">提交</Option>
                                <Option value="2">退回</Option>
                                <Option value="3">拒绝</Option>
                            </Select>
                        </FormItem>
                    </Row>
                    <Row>
                        <FormItem label="退回" prop="backOpinion"   v-if="channelEntry.approve =='2'">
                            <Select v-model="channelEntry.backOpinion" style="width:400px"  placeholder="请选择退回原因" class="w200" @on-change="changeRemark" >
                                <Option v-for="item in backOpinion" :value="item.title" :key="item.title">{{ item.title }} </Option>
                            </Select>
                        </FormItem>
                    </Row>
                    <Row>
                        <FormItem label="拒绝" prop="refusalReason" v-if="channelEntry.approve =='3'"  >
                            <Select v-model="channelEntry.refusalReason" style="width:400px"  placeholder="请选择拒绝原因" @on-change="changeRemark" class="w200">
                                <Option v-for="item in refusalReason" :value="item.title" :key="item.title">{{ item.title }} </Option>
                            </Select>
                        </FormItem>
                    </Row>
                    <Row>
                        <FormItem label="备注" prop="remark">
                            <Input v-model="channelEntry.remark" style="width:600px" class="w200"  placeholder="请输入" type="textarea" :rows="2"/>
                        </FormItem>
                    </Row>
                    <Row>
                        <Form-item label="经纬度范围（km）" prop="longitudeLatitudeRange"  v-if="isShowRange =='1'"
                                   :rules="Number(this.channelEntry.approve) !=1?noLongitudeLatitudeRange:longitudeLatitudeRange" >
                            <Input type="text" clearable class="w200" v-model.trim="channelEntry.longitudeLatitudeRange"/>
                        </Form-item>
                    </Row>

                    <Row>
                        <Form-item style="margin-left:-15px;" class="br">
                            <Button size="default" type="primary" @click="submitWorkFlow" :loading="submitLoading">提交</Button>
                            <Button size="default" type="primary" @click="returnBack">返回</Button>
                        </Form-item>
                    </Row>

                </Card>
            </Form>

            <div v-show="basicInfoGroup">
                <basic-info ref="basicInfo"  ></basic-info>   <!--@passmsg="queryChannelInfo"-->
            </div>

            <div v-show="accountInfoGroup">
                <account-info ref="accountInfo"></account-info>
            </div>

            <!--<div v-show="attachmentInfoGroup">
                <attachment-info ref="attachmentInfo"></attachment-info>
            </div>-->
            <div v-if="attachmentInfoGroup">
                <!--附件-->
                <file-operation  :uploadParam="uploadParam" :isInt="canUpload" :path="path" :readOnly="readOnly"></file-operation>
            </div>

        </div>
    </div>
</template>

<script>
    import { getDictDataByType } from "@/projects/basic/api/admin/datadic";
    import {
        approveDirectCarDealerWorkFlow,
        getRecordDetails,
    } from "@/projects/afs-channel/api/workflow/workflow";
    import {formOperation} from "@/libs/utils/form-operation-util";
    import approveBasic from "_p/afs-channel/pages/car-dealer/direct-car-dealer/direct-car-dealer-approve/driectCarDealerApproveBasic.vue";
    import BasicInfo from "_p/afs-channel/pages/car-dealer/direct-car-dealer/basic-info/directCarDealerBasicInfo.vue";
    import AccountInfo from "_p/afs-channel/pages/car-dealer/direct-car-dealer/payment-account/directCarDealerAccountInfo.vue";
    import AttachmentInfo from "_p/afs-channel/pages/car-dealer/direct-car-dealer/attachment-info/attachmentInfo.vue";
    import {
        getChannelBasicInfoById,
    } from  "@/projects/afs-channel/api/dealer/dealer";
    import FileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";

    export default {
        components: {
            'approveBasic':approveBasic,
            'BasicInfo':BasicInfo,
            'AccountInfo':AccountInfo,
            //'AttachmentInfo':AttachmentInfo,
            FileOperation,
        },
        computed:{

        },
        props: {

        },
        data () {
            return {
                //审批记录
                recordDetails:[],
                //附件部分
                uploadParam: {
                    busiNo: "",
                    belongNo: "",
                    busiType: "",
                    busiData: {}
                },
                canUpload:true,
                readOnly:true,
                path:"channel",

                isShowRange:"",
                bizDataId:"",
                channelId:"",
                carDealerId:"",
                submitLoading: false,
                basicInfoGroup:true,
                accountInfoGroup:false,
                recordInfoGroup:false,
                useInfoGroup:false,
                attachmentInfoGroup:false,
                archivesLogGroup:false,
                useInfoGroup:false,
                //拒绝原因
                refusalReason:[],
                backOpinion:[],
                channelEntry: {
                    channelInfo: {},
                    approve:"",
                    remark:"",
                    backOpinion:"",
                    refusalReason:"",
                    channelDeposit:"",
                    longitudeLatitudeRange:"",
                },
                //规则
                channelFormRules:{
                    approve:[
                        { required: true, message: "审批意见不能为空", trigger: "change"}
                    ],
                },

                longitudeLatitudeRange:[
                    { required: true, message: "经纬度范围不能为空", trigger: "change"}
                ],
                noLongitudeLatitudeRange:[
                    { required: false}
                ],

            }
        },
        mounted () {
            this.init();
            if(this.carDealerId){
                this.initGetFilterParams();
            }
        },
        methods: {
            init(){
                this.getdic();
                this.bizDataId = this.afs.getPageParams(this).bizDataId;
                //车商id
                this.carDealerId = this.afs.getPageParams(this).carDealerId;
                //渠道id
                this.channelId =this.afs.getPageParams(this).channelId;
                //是否展示经纬度范围
                this.isShowRange = this.afs.getPageParams(this).isShowRange;

                this.queryChannelInfo(this.channelId);

                this.basicInfoView("0");
                this.channel(this.afs.getPageParams(this).carDealerId);
                this.bottonView("1");
               // this.changeTypeCode(this.afs.getPageParams(this).type);
                this.$refs.basicInfo.getChannelId(this.channelId);

                //表示修改或查看
                this.changeTypeCode("0");
                this.$refs.basicInfo.getOldChannelId2(this.afs.getPageParams(this).channelId);
                this.$refs.accountInfo.changeTypeCode();
                this.getRecordDetails(this.afs.getPageParams(this).bizDataId);
                this.$refs.basicInfo.ShowSaleMan();

                console.log(this.isShowRange,"是否展示")

            },


            changeRemark(v){
                this.channelEntry.remark = v+"  ";
            },
            clearRemark(v){
                this.channelEntry.remark ="";
            },
            getRecordDetails(v){
                let param = {
                    bizDataId:v
                }
                getRecordDetails(param).then(res => {
                    if (res.code === "0000") {
                        this.recordDetails=res.data;
                    }
                })
            },

            bottonView(flag){
                this.typeCode=flag;
            },
            changeTypeCode(v){
                this.$refs.basicInfo.changeTypeCode(v);
            },

            channel(v){
                //渠道基本信息获取
                this.$refs.basicInfo.getChannelInfo(v);
                //收款账号信息获取
                this.$refs.accountInfo.getAccountInfo(v);
                //授权区域
                // this.$refs.basicInfo.getMainAreaList(v);
                //主营品牌
                this.$refs.basicInfo.getBaseTreeList(v);
                //授权车型
                this.$refs.basicInfo.getCarsTreeList(v);
            },
            basicInfoView(v){
                //授权区域初始化
                //  this.$refs.basicInfo.getMainAreaList();
                //主营品牌树初始化
                this.$refs.basicInfo.getBaseTreeList();
                //授权车型树初始化
                this.$refs.basicInfo.getCarsTreeList();
                //基础信息
                this.$refs.basicInfo.readOnlyInfo(v);
                //收款账号信息
                this.$refs.accountInfo.readOnlyInfo(v);
            },


            directCarDealerInfoView(v){
                this.$refs.basicInfo.init();
                //授权区域初始化
                this.$refs.basicInfo.getMainAreaList();
                //主营品牌树初始化
                this.$refs.basicInfo.getBaseTreeList();
                //授权车型树初始化
                this.$refs.basicInfo.getCarsTreeList();
                //渠道基本信息获取
                this.$refs.basicInfo.getChannelInfo(v);
                //收款账号信息获取
                this.$refs.accountInfo.getAccountInfo(v);
                //授权区域
                this.$refs.basicInfo.getMainAreaList(v);
                //主营品牌
                this.$refs.basicInfo.getBaseTreeList(v);
                //授权车型
                this.$refs.basicInfo.getCarsTreeList(v);
                this.$refs.basicInfo.readOnlyInfo("0");
                this.$refs.accountInfo.readOnlyInfo("0");
                this.$refs.accountInfo.showRangeSwitch();
            },
            queryChannelInfo(v){
               // this.channelEntry.channelInfo=channelInfo;
                getChannelBasicInfoById(v).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.channelEntry.channelInfo=res.data[0];
                    }
                })

            },
            //设置页面禁用元素
            setDisabled(){
                if(this.isContractEntry){

                }else{

                }
            },
            //加载页面form校验
            loadForm(){
                formOperation(this.$refs.channelEntry.fields,this.formRules);
            },

            //页面提交按钮，提交流程审批
            //页面提交按钮，提交流程审批
            submitWorkFlow(){
                console.log("渠道审批开始！");
                this.$refs.channelEntry.validate(valid => {
                    if (valid) {
                        let param = {
                            approve:this.channelEntry.approve,
                            channelId:this.channelId,
                            carDealerId:this.carDealerId,
                            longitudeLatitudeRange:this.channelEntry.longitudeLatitudeRange,
                            bizDataId:this.bizDataId,
                            remark:this.channelEntry.remark,
                            backOpinion:this.channelEntry.backOpinion,
                        }
                        console.log(param.channelId,"渠道id")
                        /*if(this.channelEntry.approve=="1"){
                            this.$refs.basicInfo.check();
                            if(this.inputRangeSwitch=="1"){
                                this.$Message.error("请输入经纬度范围");
                                return false;
                            }
                        }*/

                        approveDirectCarDealerWorkFlow(param).then(res => {
                            if (res.code === "0000") {
                                this.$Message.success("提交成功");
                                this.afs.closeTab(this);
                            }
                        }).catch(() => {
                            this.$Message.error("提交失败");
                            this.$parent.spinShow=false;
                        });
                    }
                });
            },

            //返回按钮
            returnBack(){
                //关闭页面
                this.afs.closeTab(this);
            },

            //展示基本信息
            showBasic(){
                this.basicInfoGroup=true;
                this.accountInfoGroup=false;
                this.attachmentInfoGroup=false;
            },
            //展示收款账号信息
            showAccount(){
                this.accountInfoGroup=true;
                this.basicInfoGroup=false;
                this.attachmentInfoGroup=false;
            },
            //展示附件信息
            showAttachment(){
                this.attachmentInfoGroup=true;
                this.basicInfoGroup=false;
                this.accountInfoGroup=false;
            },

            initGetFilterParams() {
                this.uploadParam.busiNo =  this.carDealerId;
                this.uploadParam.belongNo =  this.channelId;
                this.uploadParam.busiData = {};
                this.uploadParam.busiType = "carDealerApply";
            },
            // 获取数据字典
            getdic() {
                getDictDataByType("refusalReason").then(res => {
                    if (res.code === "0000") {
                        this.refusalReason = res.data;
                    }
                });
                getDictDataByType("backOpinion").then(res => {
                    if (res.code === "0000") {
                        this.backOpinion = res.data;
                    }
                });
            },
        }
    }

</script>
<style  scoped>
    .div-entry {
        height: 95%;
        width: 75%;
        float: left;
        overflow-y: scroll;
        overflow-x: hidden;
    }
    .recordInfo_search {
        font-size: 15px;
        padding-left: 395px;
        line-height: 40px;
        font-weight: bold;
        text-align: left;
        word-spacing: 25px;
        color: #3e95d4;
    }

</style>
